package com.fly.autoconfigure;

import feign.RequestInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;

/**
 * @description feign请求拦截器（全局）
 * @author: fly
 * @date: 2018/11/28 10:59
 */
@Configuration
public class FeignClientAutoConfiguration {

    @Bean
    @ConditionalOnBean(OAuth2ClientContext.class)
    public RequestInterceptor oauth2FeignRequestInterceptor(OAuth2ClientContext oauth2ClientContext, OAuth2ProtectedResourceDetails auth2ProtectedResourceDetails){
        return new OAuth2FeignRequestInterceptor(oauth2ClientContext, auth2ProtectedResourceDetails);
    }
}